home *** CD-ROM | disk | FTP | other *** search
- /* bob.c - the main routine */
- /*
- Copyright (c) 1991, by David Michael Betz
- All rights reserved
- */
-
- #include <stdio.h>
- #include <stdarg.h>
- #include <setjmp.h>
- #include "bob.h"
-
- #ifdef MACINTOSH
- #include <console.h>
- #endif
-
- /* Revision history
-
- 1.0 08/15/91 Initial version for DDJ article.
- 1.1 08/20/91 Fixed do_for to allow null statements.
- 1.2 08/28/91 Fixed problem with newobject().
- 1.3 09/27/91 Fixed a bug in compact_vector().
- 1.4 10/09/91 Reworked for Windows 3 - part 1.
- 1.5 10/12/91 Various bug fixes. Added gc().
- */
-
- #define BANNER "Bob v1.5 - Copyright (c) 1991, by David Betz"
-
- /* global variables */
- jmp_buf error_trap;
- char **bobargv;
- int bobargc;
-
- /* external variables */
- extern int decode,trace;
- extern VALUE symbols;
- extern VALUE stdin_iostream;
- extern VALUE stdout_iostream;
- extern VALUE stderr_iostream;
-
- /* forward declarations */
- #ifdef __STDC__
- static void compile_file(char *);
- static void add_file(char *,FILE *,VALUE *);
- #endif
-
- /* main - the main routine */
- main(int argc, char *argv[])
- {
- char fullname[20];
- int i;
-
- /* display the banner */
- osputs(BANNER);
- osputs("\n");
-
- #ifdef MACINTOSH
- argc = ccommand(&argv);
- #endif
-
- /* initialize */
- initialize(SMAX);
- init_compiler();
- bobargc = argc - 1;
- bobargv = argv + 1;
-
- /* setup the standard i/o streams */
- add_file("stdin",stdin,&stdin_iostream);
- add_file("stdout",stdout,&stdout_iostream);
- add_file("stderr",stderr,&stderr_iostream);
-
- /* load and execute some code */
- for (i = 1; i < argc; ++i)
- if (strcmp(argv[i],"-d") == 0)
- decode = 1;
- else if (strcmp(argv[i],"-t") == 0)
- trace = 1;
- else {
- strcpy(fullname,argv[i]);
- strcat(fullname,".bob");
- compile_file(fullname);
- }
- if (!execute("main"))
- printf("Error: executing 'main'\n");
- }
-
- /* compile_file - compile definitions in a file */
- static void compile_file(name)
- char *name;
- {
- FILE *ifp;
- if ((ifp = fopen(name,"r")) != NULL) {
- compile_definitions(fgetc,ifp);
- fclose(ifp);
- }
- }
-
- /* info - display progress information */
- void info(char *fmt, ...)
- {
- char buf1[100],buf2[100];
- va_list args;
-
- va_start(args, fmt);
- vsprintf(buf1,fmt,args);
- va_end(args);
- sprintf(buf2,"[ %s ]\n",buf1);
- osputs(buf2);
- }
-
- /* error - print an error message and exit */
- void error(char *fmt, ...)
- {
- char buf1[100],buf2[100];
- va_list args;
-
- va_start(args,fmt);
- vsprintf(buf1,fmt,args);
- va_end(args);
- sprintf(buf2,"Error: %s\n",buf1);
-
- osputs(buf2);
- longjmp(error_trap,1);
- }
-
- void osputs(str)
- char *str;
- {
- fputs(str,stderr);
- }
-
- /* add_file - add a built-in file */
- static void add_file(name,fp,pval)
- char *name; FILE *fp; VALUE *pval;
- {
- extern IODISPATCH fileio;
- DICT_ENTRY *sym;
- sym = addentry(&symbols,name,ST_SDATA);
- set_iostream(&sym->de_value,newiostream(&fileio,fp));
- *pval = sym->de_value;
- }
-